package top.hcode.hoj.manager.coll;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.hcode.hoj.dao.collect.CollHonorRecordDao;
import top.hcode.hoj.pojo.entity.coll.CollHonorRecord;

import java.util.List;

/**
 * @author orangej
 * @since 2025/1/21
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ItechCollHonorRecordManager {
    private final CollHonorRecordDao honorRecordDao;
    public List<CollHonorRecord> getHonorRecordList(String uid, String collId) {
        return honorRecordDao.getHonorRecordList(uid, collId);
    }

    public CollHonorRecord deleteHonorRecord(String uid, Long id) {
        String strId = String.valueOf(id);
        CollHonorRecord record = honorRecordDao.getById(strId);
        if (record != null && record.getUserId().equals(uid)) {
            honorRecordDao.removeById(strId);
        }

        return record;
    }

    public CollHonorRecord saveHonorRecord(CollHonorRecord record) {
        honorRecordDao.saveOrUpdate(record);
        return record;
    }

    public Integer countHonorRecord(String uid, String collId) {
        return honorRecordDao.countHonorRecord(uid, collId);
    }
}
